package net.csdn.business.kanban.api.controller;

/**
 * @ClassName KanbanDetailController
 * @Description TODO
 * @Author liuzhisheng
 * @Date 2023/9/14
 **/
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import net.csdn.business.kanban.api.facade.IssueFacade;
import net.csdn.business.kanban.api.facade.KanbanViewFacade;
import net.csdn.business.kanban.api.service.KanbanViewService;
import net.csdn.business.kanban.common.domain.DTO.IssueVoDto;
import net.csdn.business.kanban.common.domain.request.KanbanUpdateViewParam;
import net.csdn.business.kanban.common.domain.request.KanbanViewAddParam;
import net.csdn.business.kanban.common.domain.request.KanbanViewMoveParam;
import net.csdn.business.kanban.common.domain.resp.KanbanViewResp;
import net.csdn.business.kanban.feign.annotation.Inner;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@Inner
@RestController
@RequestMapping("/api/v1/kanban/view")
@RequiredArgsConstructor
@Api(tags = "看板view")
public class KanbanViewController {
    private final KanbanViewService kanbanViewService;
    private final IssueFacade issueFacade;
    private final KanbanViewFacade kanbanViewFacade;

    @PostMapping("/{kanbanId}")
    @ApiOperation(value = "view 新增和复制")
    public boolean addOrCopeKanbanView(@PathVariable("kanbanId") String kanbanId,
                                       @Validated @RequestBody KanbanViewAddParam kanbanViewAddParam){
        return kanbanViewFacade.addOrCopeKanbanView(kanbanId,kanbanViewAddParam);
    }

    @PutMapping
    @ApiOperation(value = "view 编辑(view名称、过滤条件,字段显示隐藏)")
    public boolean updateKanbanView(@Validated @RequestBody KanbanUpdateViewParam param) {
        return kanbanViewFacade.updateKanbanView(param);
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "view 删除")
    public boolean deleteKanbanView(@PathVariable("id") Long id) {
        return kanbanViewService.removeById(id);
    }

    @GetMapping("/list/{kanbanId}")
    @ApiOperation(value = "view 列表")
    public List<KanbanViewResp> getAllViewsByKanban(@PathVariable("kanbanId") String kanbanId) {
        return kanbanViewFacade.getAllViewsByKanban(kanbanId);
    }

    @PutMapping("/move")
    @ApiOperation(value = "view 视图移动位置")
    public boolean moveView(@Validated @RequestBody KanbanViewMoveParam kanbanViewMoveParam){
        return kanbanViewFacade.moveView(kanbanViewMoveParam);
    }


    @ApiOperation(value = "获取issues")
    @GetMapping("/issues/{projectId}/{kanbanId}")
    public List<IssueVoDto> issues(@PathVariable("projectId") Long projectId,
                                   @PathVariable("kanbanId") String kanbanId,
                                   @RequestParam(value = "searchBy",required = false) String searchBy){
        return issueFacade.getIssues(projectId,kanbanId,searchBy);
    }
}

